const binary_search = (sourceItems, target) => {
    let lowIndex = 0;
    let highIndex = sourceItems.length - 1;
    while(lowIndex <= highIndex){
        let midIndex = Math.floor((lowIndex + highIndex) / 2);
        let midValue = sourceItems[midIndex];
        if(midValue == target)
            return midIndex;
        if(midValue > target){
            highIndex = midIndex - 1;
        }else{
            lowIndex = midIndex + 1;
        }
    }
    return -1;
};

const sourceItems = [1,2,3,4,5,6,7,8,9,10];
const target = 6;
binary_search(sourceItems, target);

